home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / Mac F2C 1.2.2 / MPW Support / F2CExamples / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-08  |  3.4 KB  |  190 lines  |  [TEXT/MPS ]

  1. /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */
  2.  
  3.  
  4. #include "stdio.h"
  5. #include "signal.h"
  6.  
  7. #ifndef SIGIOT
  8. #ifdef SIGABRT
  9. #define SIGIOT SIGABRT
  10. #endif
  11. #endif
  12.  
  13. #if defined(THINK_C) || defined(THINK_CPLUS)
  14. #include <console.h>    /* IMT 2 Dec 94 Needed to make command line work under THINK */
  15. #endif
  16.  
  17. #ifdef __MWERKS__        /* IMT 2 Dec 94 Needed for MetroWerks (from Dirk Froehling) */
  18. //#include <SIOUX.h>
  19. #endif
  20.  
  21. #ifndef KR_headers
  22. #include "stdlib.h"
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. #ifdef NO__STDC
  29. #define ONEXIT onexit
  30. extern void f_exit();
  31. #else
  32. #ifndef KR_headers
  33. extern void f_exit(void);
  34. #ifndef NO_ONEXIT
  35. #define ONEXIT atexit
  36. extern int atexit(void (*)(void));
  37. #endif
  38. #else
  39. #ifndef NO_ONEXIT
  40. #define ONEXIT onexit
  41. extern void f_exit();
  42. #endif
  43. #endif
  44. #endif
  45.  
  46. #ifdef KR_headers
  47. extern void f_init(), sig_die();
  48. extern int MAIN__();
  49. #define Int /* int */
  50. #else
  51. extern void f_init(void), sig_die(char*, int);
  52. extern int MAIN__(void);
  53. #define Int int
  54. #endif
  55.  
  56. static void sigfdie(Int n)
  57. {
  58. sig_die("Floating Exception", 1);
  59. }
  60.  
  61.  
  62. static void sigidie(Int n)
  63. {
  64. sig_die("IOT Trap", 1);
  65. }
  66.  
  67. #ifdef SIGQUIT
  68. static void sigqdie(Int n)
  69. {
  70. sig_die("Quit signal", 1);
  71. }
  72. #endif
  73.  
  74.  
  75. static void sigindie(Int n)
  76. {
  77. sig_die("Interrupt", 0);
  78. }
  79.  
  80. static void sigtdie(Int n)
  81. {
  82. sig_die("Killed", 0);
  83. }
  84.  
  85. #ifdef SIGTRAP
  86. static void sigtrdie(Int n)
  87. {
  88. sig_die("Trace trap", 1);
  89. }
  90. #endif
  91.  
  92.  
  93. /* The following function written by Dirk Froehling; modified by IMT */
  94.  
  95. #if defined(THINK_C) || defined(THINK_CPLUS) 
  96.  
  97. #include <Files.h>
  98. #include <Processes.h>
  99.  
  100.  
  101. static void SetDefVolToAppVol(void)
  102. {
  103.     ProcessSerialNumber    currentPSN;
  104.     ProcessInfoRec        info;
  105.     FSSpec                appSpec;
  106.     
  107.     OSErr                err;
  108.         
  109.     currentPSN.highLongOfPSN = 0;
  110.     currentPSN.lowLongOfPSN = kCurrentProcess;
  111.     info.processInfoLength = sizeof(ProcessInfoRec);
  112.     info.processName = NULL;
  113.     info.processAppSpec = &appSpec;
  114.     err = GetProcessInformation(¤tPSN, &info);
  115.     err = HSetVol(NULL, appSpec.vRefNum, appSpec.parID);
  116. }
  117.  
  118. #endif
  119.  
  120.  
  121.  
  122.  
  123. int xargc;
  124. char **xargv;
  125.  
  126. #ifdef KR_headers
  127. main(argc, argv) int argc; char **argv;
  128. #else
  129. main(int argc, char **argv)
  130. #endif
  131. {
  132. #if defined(THINK_C) || defined(THINK_CPLUS) || defined(__MWERKS__)
  133.  
  134. //    argc = ccommand( &argv );        /* IMT 2 Dec 94 Think/Codewarrior mod */
  135.  
  136. #endif /* Macintosh C compilers */
  137.  
  138. #if defined(THINK_C) || defined(THINK_CPLUS) 
  139.  
  140.     SetDefVolToAppVol();            /* IMT 14 Dec 94 Thanks to Dirk Froehling */
  141.  
  142. #endif /* Macintosh C compilers */
  143.  
  144. xargc = argc;
  145. xargv = argv;
  146. signal(SIGFPE, sigfdie);    /* ignore underflow, enable overflow */
  147. #ifdef SIGIOT
  148. signal(SIGIOT, sigidie);
  149. #endif
  150. #ifdef SIGTRAP
  151. signal(SIGTRAP, sigtrdie);
  152. #endif
  153. #ifdef SIGQUIT
  154. if(signal(SIGQUIT,sigqdie) == SIG_IGN)
  155.     signal(SIGQUIT, SIG_IGN);
  156. #endif
  157. if(signal(SIGINT, sigindie) == SIG_IGN)
  158.     signal(SIGINT, SIG_IGN);
  159. signal(SIGTERM,sigtdie);
  160.  
  161. #ifdef pdp11
  162.     ldfps(01200); /* detect overflow as an exception */
  163. #endif
  164.  
  165. f_init();
  166. #ifndef NO_ONEXIT
  167. ONEXIT(f_exit);
  168. #endif
  169. MAIN__();
  170. #ifdef NO_ONEXIT
  171. f_exit();
  172. #endif
  173. exit(0);    /* exit(0) rather than return(0) to bypass Cray bug */
  174. return 0;    /* For compilers that complain of missing return values; */
  175.         /* others will complain that this is unreachable code. */
  176. }
  177. #ifdef __cplusplus
  178.     }
  179. #endif
  180. int fileno(FILE *p) 
  181. {
  182.     return (int)((p)->_file);
  183. }
  184.  
  185. int isatty(int fn)
  186. {
  187. //    printf("File no = %d  : %d \n",fn,(int)(fn!=fileno(stdin) && fn!=fileno(stdout) && fn!=fileno(stderr)));
  188. //    return (int)(fn!=fileno(stdin) && fn!=fileno(stdout) && fn!=fileno(stderr));
  189.     return 0;
  190. }